<?php
/**
 * XIE--Scorpion
 *
 * 前台登陆展示
 *
 * time 2016-5-13
 */
namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB,Input,Redirect,Session,url;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    /**
	 * 登陆页面
	 */
    public function login()
    {
		if($_GET)
		{
            $user_email=$_GET['email'];
            $user_pwd=md5($_GET['password']);
			$re=DB::table('user')->where('user_email',$user_email)->where('user_pwd',$user_pwd)->get();
			if($re)
			{
                $arr=DB::select("select user_name,user_id from user where user_email='$user_email'");
				foreach($arr as $v){
				   $user_name=$v->user_name;
				   $user_id=$v->user_id;
				}
				//print_r($user_name);die;
                Session::put('user_name',$user_name);
			    Session::put('user_id',$user_id);
				return redirect('index');
			}else
			{
               echo "<script>alert('登陆失败');</script>";
			   return view('homes/login/login');
			}
		}else
		{
		   return view('homes/login/login');
		}
    }
	/**
	 * 注册页面
	 */
    public function register()
    {
		if($_GET)
		{
			//接值
			//print_r($_GET);die;
			$data['user_type']=isset($_GET['type'])?$_GET['type']:'';
			$data['user_pwd']=md5(isset($_GET['password'])?$_GET['password']:'');
			$data['user_email']=isset($_GET['email'])?$_GET['email']:'';
			$data['user_name']=isset($_GET['user_name'])?$_GET['user_name']:'';
            $data['user_phone']=isset($_GET['user_phone'])?$_GET['user_phone']:'';
			$user_id=DB::table('user')->insertGetid($data);
			if($user_id)
			{
			   Session::put('user_name',$data['user_name']);
			   Session::put('user_id',$user_id);
               echo "<script>alert('注册成功');</script>";
                return view('homes/login/login');
			}else
			{
               echo "<script>alert('注册失败');</script>";
                return view('homes/login/register');
			}
		}else
		{
            return view('homes/login/register');
		}
    }
	/**
	 * 退出
	 */
    public function login_out()
    {
	   Session::flush();
	   return redirect('index');
	}
}
?>